#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStateMachine>
#include <QState>
#include <QTimer>
#include <QPair>
#include "touchexmppclient.h"
#include "QXmppMessage.h"
#include "manager.h"
#include "xmlreader.h"
#include "channel.h"
#include "manager.h"
#include <QTabWidget>
#include "tab_widget.h"

namespace Ui
{
    class ColaborationWindow;
}

struct UserData{
    QString login;
    QString password;
};

class ColaborationWindow : public QTabWidget
{
    Q_OBJECT

public:
    ColaborationWindow(Touche::ColaborativeManager *manager, QWidget *parent = 0);
    ~ColaborationWindow();
    //ToucheXmppClient *client;
    QString diffPatchMsg(QString msg = "");
    void addUserInChannelView(QString channeSelected);
    //QMap<QString, Channel*> channels;
    bool connected;
private:
    Ui::ColaborationWindow *ui;
    QStateMachine *machine;
    Touche::ColaborativeManager * m_manager;
    //QMap<QString, Channel*> channels;
    void updateChannelsView();
    bool validateEnterChannel(QString channelSelected);

bool loginIsInChannel(QTreeWidgetItem *channel);
//    bool existsChannel(QString name);
    QHash<QString, TabWidget *> buddies;

public slots:
    //void onChatText(const QString &body,const QString &from);
    void loadBuddies();
    void connectionError(QXmppMessage);
    void contactsChanged();
    void channelsChanged();
    void on_messageReceived(QXmppMessage);
    void on_connected();

private slots:
    void on_txt_chatChannel_textChanged();
    void on_b_send_channel_clicked();
    void on_b_startPrivateChat_clicked();
    void on_remove_buddy_clicked();
    void on_enter_button_clicked();
    void on_add_buddy_clicked();
    void on_desconect_button_clicked();
    void on_b_send_buddy_clicked();
    void on_create_channel_button_clicked();
    void onTabDeleted(QObject *);
    void sendPrivateMessage(const QString&, const QString &);

    void onPrivateMessage(const QString &body, const QString &from);
    void onChannelMessage(const QString &body, const QString &from);

signals:
    void newBuddyRequest(QString);
    void buddyRemove(QString);
};

#endif // MAINWINDOW_H
